package zb.blog.base.interceptor;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import zb.blog.base.cache.DataToCache;
import zb.blog.base.sessionScope.SessionScope;
import zb.blog.bean.AuthPersonBean;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class BlogInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        AuthPersonBean authPersonBean = (AuthPersonBean) request.getSession().getAttribute("loginUser");
        if (authPersonBean != null) {
            return true;
        }
        response.sendRedirect(request.getContextPath() + "/login.html");
        return false;
    }
}
